﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections;

using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Team6_Algorithms.Filters;
//written and rewritten by whole team
namespace VisionApplication
{
    public partial class SettingsForm : Form
    {
        public Settings settings;
        Hashtable MaskTable = new Hashtable();
        

        public SettingsForm(string[] requ)
        {
            
            Masks m = new Masks();
            settings = new Settings(requ);
            MaskTable.Add("Emboss 3x3", m.Emboss3x3);
            MaskTable.Add("Emboss 5x5", m.Emboss5x5);
            MaskTable.Add("Gaussian 3x3", m.Gaussian3x3);
            MaskTable.Add("Gaussian 5x5", m.Gaussian5x5);
            MaskTable.Add("Vertical Edge Detection 3x3", m.VerticalEdgeDet3x3);
            MaskTable.Add("Horizontal Edge Detection 3x3", m.HorizontalEdgeDet3x3);
            

            
            InitializeComponent();
            foreach (string s in MaskTable.Keys)
            {
                MaskCombobox.Items.Add(s);
            }

            foreach (string req in settings.requiredList)
            {
                switch (req)
                {
                    case "size":
                        sizeBox.Enabled = true;
                        break;

                    case "percentage":
                        percBox.Enabled = true;
                        break;

                    case "rows":
                        rowBox.Enabled = true;
                        break;

                    case "width":
                        widthBox.Enabled = true;
                        break;

                    case "mask":
                        MaskCombobox.Enabled = true;

                        break;

                    case "max":
                        MaxCheckBox.Enabled = true;

                        break;

                    case "treshold":
                        TresHoldTB.Enabled = true;
                        break;

                    case "HSL":
                        HueLow.Enabled = true;
                        HueHigh.Enabled = true;
                        SaturationLow.Enabled = true;
                        SaturationHigh.Enabled = true;
                        LightnessLow.Enabled = true;
                        LightnessHigh.Enabled = true;
                        break;

                }

            }
            if (requ == null || requ.Length == 0)
            {
                this.DialogResult = DialogResult.OK;
                
            }



        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (sizeBox.Enabled == true)
                {
                    settings.Size = Convert.ToInt32(sizeBox.Text);
                    if (settings.Size % 2 == 0)
                    {
                        MessageBox.Show("odd numbers only.");
                        return;
                    }
                }

                if (TresHoldTB.Enabled == true)
                {
                    settings.TresHold = Convert.ToInt32(TresHoldTB.Text);
                    
                }

                if (percBox.Enabled == true)
                {
                    settings.Percentage = Convert.ToInt32(percBox.Text);
                }
                if (rowBox.Enabled == true)
                {
                    settings.Rows = Convert.ToInt32(rowBox.Text);
                }
                if (widthBox.Enabled == true)
                {
                    settings.Width = Convert.ToInt32(widthBox.Text);
                }
                if (MaskCombobox.Enabled == true)
                {
                    settings.mask = (Mask) MaskTable[(string) MaskCombobox.SelectedItem];
                    settings.MaskName = (string)MaskCombobox.SelectedItem;
                }
                if (MaxCheckBox.Enabled == true)
                {
                    settings.Max = MaxCheckBox.Checked;
                }
                if (HueLow.Enabled == true)
                {
                 settings.HueLow = Convert.ToInt32(HueLow.Text);
                 settings.HueHigh = Convert.ToInt32(HueHigh.Text);
                 settings.SaturationLow = Convert.ToInt32(SaturationLow.Text);
                 settings.SaturationHigh = Convert.ToInt32(SaturationHigh.Text);
                 settings.LightnessLow = Convert.ToInt32(LightnessLow.Text);
                 settings.LightnessHigh = Convert.ToInt32(LightnessHigh.Text);
                }


                this.DialogResult = DialogResult.OK;
            }
            catch(Exception ASd)
            {
                MessageBox.Show("Numbers only." + ASd);
            }
        }

        private void sizeBox_Click(object sender, EventArgs e)
        {
            TextBox b = (TextBox) sender;
            if (b.Enabled == true)
            {
                b.Text = "";
            }
        }

        private void percBox_Click(object sender, EventArgs e)
        {
            if (percBox.Enabled == true)
            {
                percBox.Text = "";
            }
        }

        private void rowBox_Click(object sender, EventArgs e)
        {
            if (rowBox.Enabled == true)
            {
                rowBox.Text = "";
            }
        }

        private void widthBox_Click(object sender, EventArgs e)
        {
            if (widthBox.Enabled == true)
            {
                widthBox.Text = "";
            }
        }

        private void checkEnter(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                button1_Click(null, null);
            }
        }
    }
}
